#include <bits/stdc++.h>
using namespace std;
struct PROGRAM {
  int s;
  int t;
};
PROGRAM pro[200001];

// 排序：先结束的节目优先。如果结束时间相等，先开始的节目优先。
bool guize(PROGRAM a, PROGRAM b) {
  if (a.t < b.t || a.t == b.t && a.s < b.s)
    return true;
  else
    return false;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> pro[i].s >> pro[i].t;
  }
  sort(pro + 1, pro + n + 1, guize);

  int ans = 0;
  int curTime = 0;
  for (int i = 1; i <= n; i++) {
    int begin = pro[i].s;
    if (begin >= curTime) {
      ans++;
      curTime = pro[i].t;
    }
  }
  cout << ans;
  return 0;
}